package com.seocoo.worker.order.widget;

import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.seocoo.worker.R;
import com.seocoo.worker.base.refresh.SpaceItemDecoration;
import com.seocoo.worker.order.widget.adapter.OrderDetailParticularsAdapter;
import com.seocoo.worker.order.widget.rsp.RspOrderDetailParticulars;

import java.util.List;

/***
 *订单详情明细布局
 */
public class OrderDetailParticularsView extends ConstraintLayout {

    private RecyclerView recycleView;
    private TextView tv_title;
    private TextView tv_line;
    private OrderDetailParticularsAdapter adapter;

    public OrderDetailParticularsView(Context context) {
        super(context);
        initView(context);
    }

    public OrderDetailParticularsView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public OrderDetailParticularsView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        View view = inflate(context, R.layout.order_detail_particulars_layout, this);
        tv_title = view.findViewById(R.id.tv_title);
        tv_line = view.findViewById(R.id.tv_line);
        recycleView = view.findViewById(R.id.recycler_view);
        recycleView.setLayoutManager(new LinearLayoutManager(context));
        recycleView.addItemDecoration(new SpaceItemDecoration(15));
        adapter = new OrderDetailParticularsAdapter();
        recycleView.setAdapter(adapter);
        tv_line.setVisibility(GONE);
    }

    public void initData(List<RspOrderDetailParticulars> data) {
        if (adapter == null) {
            return;
        }
        adapter.setNewData(data);
    }

    public BaseQuickAdapter getAdapter() {
        return this.adapter;
    }

    public void setTv_title(String title) {
        if (TextUtils.isEmpty(title)) {
            tv_line.setVisibility(GONE);
            tv_title.setVisibility(GONE);
        } else {
            tv_line.setVisibility(VISIBLE);
            tv_title.setVisibility(VISIBLE);
            tv_title.setText(title);
        }
    }

}
